home *** CD-ROM | disk | FTP | other *** search
/ MacFormat España 4 / MacFormat n. 4 (Spain) / MacFormat 4.bin / La ciudad del ShareWare / Desarrollo / ICAppSourceKit1.0 / ICEvents.p < prev    next >
Encoding:
Text File  |  1994-11-27  |  6.9 KB  |  317 lines

  1. unit ICEvents;
  2.  
  3. interface
  4.  
  5.     const
  6.         M_Apple = 128;
  7.  
  8.     procedure HandleEvents;
  9.  
  10. implementation
  11.  
  12.     uses
  13.         EPPC, AppleEvents, ICGlobals, ICDocument, ICWindows, ICMiscSubs, ICInstall;
  14.  
  15.     procedure DoDiskEvent (message: longInt);
  16.         var
  17.             pt: point;
  18.             oe: OSErr;
  19.     begin
  20.         if (HiWord(message) <> noErr) then begin
  21.             pt.h := ((screenbits.bounds.Right - screenbits.bounds.Left - 304) div 2);
  22.             pt.v := ((screenbits.bounds.Bottom - screenbits.bounds.Top - 156) div 3);
  23.             InitCursor;
  24.             oe := DIBadMount(pt, message);
  25.         end;
  26.     end;
  27.  
  28.     procedure DoActivateDeactivate (window: WindowPtr; activate: boolean);
  29.     begin
  30.         if activate then begin
  31.             SelectWindow(window);
  32.         end; (* if *)
  33.         WindowActivateDeactivate(window, activate);
  34.     end;
  35.  
  36.     procedure DoSuspendResume (resume: boolean);
  37.     begin
  38.         in_foreground := resume;
  39.         if FrontWindow <> nil then begin
  40.             DoActivateDeactivate(FrontWindow, resume);
  41.         end;
  42.         InitCursor;
  43.     end;
  44.  
  45.     procedure DoUpdate (window: WindowPtr);
  46.     begin
  47.         BeginUpdate(window);
  48. (* *)
  49.         EndUpdate(window);
  50.     end;
  51.  
  52.     procedure DoKey (er: EventRecord);
  53.     begin
  54.         WindowsDoKey(er);
  55.     end;
  56.  
  57.     procedure DoAutoKey (er: EventRecord);
  58.     begin
  59.         DoKey(er);
  60.     end;
  61.  
  62.     procedure AdjustMenus;
  63.     begin
  64.         WindowsAdjustMenus;
  65.     end; (* AdjustMenus *)
  66.  
  67.     procedure AdjustAllMenus;
  68.     begin
  69.         AdjustMenus;
  70.         SetItemEnable(GetMHandle(M_File), FM_Close, IsDocOpen or (GetWindowType(FrontWindow) = WT_About));
  71.         SetItemEnable(GetMHandle(M_File), FM_Save, IsDocDirty or IsDocNew);
  72.         SetItemEnable(GetMHandle(M_File), FM_SaveAs, IsDocOpen);
  73.         AdjustInstalMenu(M_Install);
  74.         if IsDocOpen then begin
  75.             SetItem(GetMHandle(M_Windows), 1, GetDocumentName);
  76.         end
  77.         else begin
  78.             SetItem(GetMHandle(M_Windows), 1, GetAString(128, 15));
  79.         end; (* if *)
  80.     end;
  81.  
  82.     procedure DoIdle;
  83.     begin
  84.         WindowsIdle;
  85.     end;
  86.  
  87.     procedure DoMenu (menu: integer; item: integer);
  88.         var
  89.             DAName: Str255;
  90.             junk: OSErr;
  91.             loe: longint;
  92.             err: OSErr;
  93.     begin
  94.         case menu of
  95.             M_Apple:  begin
  96.                 case item of
  97.                     1: 
  98.                         DisplayError(acOpenWindow, WindowsOpen(WT_About, 128));
  99.                     2: 
  100.                         ;
  101.                     otherwise begin
  102.                         GetItem(GetMHandle(M_apple), item, DAName);
  103.                         junk := OpenDeskAcc(DAName);
  104.                     end
  105.                 end; (* case *)
  106.             end;
  107.             M_File:  begin
  108.                 case item of
  109.                     FM_New:  begin
  110.                         DisplayError(acNewDocument, DoNewDoc);
  111.                     end;
  112.                     FM_Open: 
  113.                         DisplayError(acOpenDocument, DoSFOpen);
  114.                     FM_OpenInternetPreferences: 
  115.                         DisplayError(acOpenDocument, DoOpenInternetPreferences);
  116.                     FM_Close: 
  117.                         DisplayError(acCloseWindow, DoCloseDocWindow(FrontWindow));
  118.                     FM_Save: 
  119.                         DisplayError(acSave, DoSave);
  120.                     FM_SaveAs: 
  121.                         DisplayError(acSave, DoSaveAs);
  122.                     FM_Quit: 
  123.                         DisplayError(acQuit, DoQuit);
  124.                     otherwise
  125.                         ;
  126.                 end; (* case *)
  127.             end;
  128.             M_Edit:  begin
  129.                 case item of
  130.                     EM_Undo, EM_Cut, EM_Copy, EM_Paste, EM_Clear, EM_SelectAll:  begin
  131.                         WindowsDoEditMenu(item);
  132.                     end;
  133.                     otherwise
  134.                         ;
  135.                 end;
  136.             end;
  137.             M_Install:  begin
  138.                 DoInstallMenu(menu, item);
  139.             end;
  140.             M_Windows:  begin
  141.                 DisplayError(acOpenWindow, WindowsOpen(WindowType(ord(WT_Main) + item - 1), 200 + item - 1));
  142.             end;
  143.             otherwise
  144.                 ;
  145.         end; (* case *)
  146.         if not quitNow then begin
  147.             HiliteMenu(0);
  148.         end;
  149.     end; (* DoMenu *)
  150.  
  151.     procedure DoMainClick (er: eventRecord; wp: windowPtr; code: integer);
  152.         var
  153.             mResult: longInt;
  154.             needsselect: boolean;
  155.             tempRect: Rect;
  156.     begin
  157.         needsselect := (wp <> nil) & (wp <> FrontWindow);
  158.         if needsselect & not (code in [inDrag, inContent]) then begin
  159.             SelectWindow(wp);
  160.         end;
  161.         case code of
  162.             inMenuBar:  begin
  163.                 AdjustAllMenus;
  164.                 mResult := MenuSelect(er.where);
  165.                 if mResult <> 0 then begin
  166.                     DoMenu(HiWord(mResult), LoWord(mResult));
  167.                 end; (* if *)
  168.                 if not quitNow then begin
  169.                     HiliteMenu(0);
  170.                 end; (* if *)
  171.             end;
  172.             InDrag:  begin
  173.                 if needsselect and (BAND(er.modifiers, cmdKey) = 0) then begin
  174.                     SelectWindow(wp);
  175.                 end; (* if *)
  176.                 SetPort(wp);
  177.                 tempRect := GetGrayRgn^^.rgnBBox;
  178.                 DragWindow(wp, er.where, tempRect);
  179.             end;
  180.             inGrow: 
  181.                 ;
  182.             inZoomIn, inZoomOut: 
  183.                 ;
  184.             inGoAway:  begin
  185.                 if TrackGoAway(wp, er.where) then begin
  186.                     DisplayError(acCloseWindow, DoCloseDocWindow(wp));
  187.                 end;
  188.             end;
  189.             inContent:  begin
  190.                 if needsselect then begin
  191.                     SelectWindow(wp);
  192.                 end;
  193.             end;
  194.             inSysWindow: 
  195.                 SystemClick(er, wp);
  196.             otherwise
  197.  
  198.         end;
  199.     end;
  200.  
  201.     procedure DimMenuTitles;
  202.         var
  203.             mh: MenuHandle;
  204.             flags: longint;
  205.             i: integer;
  206.             old_enable_title: boolean;
  207.             enable_title: boolean;
  208.             menu_bar_redraw: boolean;
  209.     begin
  210.         AdjustMenus;
  211.         (* edit *)
  212.         mh := GetMHandle(M_Edit);
  213.         flags := mh^^.enableFlags;
  214.         old_enable_title := btst(flags, 0);
  215.         enable_title := false;
  216.         for i := 1 to CountMItems(mh) do begin
  217.             if btst(flags, i) then begin
  218.                 enable_title := true;
  219.                 leave;
  220.             end; (* if *)
  221.         end; (* for *)
  222.         SetItemEnable(mh, 0, enable_title);
  223.         menu_bar_redraw := (enable_title <> old_enable_title);
  224.         (* windows *)
  225.         mh := GetMHandle(M_Windows);
  226.         flags := mh^^.enableFlags;
  227.         old_enable_title := btst(flags, 0);
  228.         enable_title := IsDocOpen;
  229.         SetItemEnable(mh, 0, enable_title);
  230.         menu_bar_redraw := menu_bar_redraw or (enable_title <> old_enable_title);
  231.         (*  *)
  232.         if menu_bar_redraw then begin
  233.             DrawMenuBar;
  234.         end; (* if *)
  235.     end; (* DimMenuTitles *)
  236.  
  237.     procedure HandleEvents;
  238.         var
  239.             junkbool: boolean;
  240.             er: EventRecord;
  241.             code: integer;
  242.             wp: WindowPtr;
  243.             ch: char;
  244.             mResult: longint;
  245.             junk: OSErr;
  246.             b: boolean;
  247.             item: integer;
  248.     begin
  249.         DimMenuTitles;
  250.         junkbool := WaitNextEvent(everyEvent, er, 10, nil);
  251.         ch := chr(BAND(er.message, CharCodeMask));
  252.         DoIdle;
  253.         b := true;
  254.         if WindowsEarlyHandleEvent(er) then begin
  255.             b := false;
  256.         end;
  257.         if b & ((er.what = keyDown) or (er.what = autoKey)) then begin
  258.             if BAND(er.modifiers, CmdKey) <> 0 then begin
  259.                 AdjustAllMenus;
  260.                 mResult := MenuKey(ch);
  261.                 if mResult <> 0 then begin
  262.                     DoMenu(HiWord(mResult), LoWord(mResult));
  263.                     b := false;
  264.                 end;
  265.             end;
  266.             if b & WindowsEarlyHandleKey(er) then begin
  267.                 b := false;
  268.             end;
  269.         end;
  270.         if b & IsDialogEvent(er) then begin
  271.             if DialogSelect(er, wp, item) then begin
  272.                 WindowItemWhere(wp, er, item);
  273.                 b := false;
  274.             end;
  275.         end;
  276.         if b then begin
  277.             case er.what of
  278.                 MouseDown:  begin
  279.                     code := FindWindow(er.where, wp);
  280.                     if wp = nil then begin
  281.                         wp := FrontWindow;
  282.                     end;
  283.                     DoMainClick(er, wp, code);
  284.                 end;
  285.  
  286.                 KeyDown:  begin
  287.                     DoKey(er);
  288.                 end;
  289.  
  290.                 AutoKey: 
  291.                     DoAutoKey(er);
  292.  
  293.                 UpdateEvt: 
  294.                     DoUpdate(windowPtr(er.message));
  295.  
  296.                 ActivateEvt: 
  297.                     DoActivateDeactivate(windowPtr(er.message), odd(er.modifiers));
  298.  
  299.                 kOSEvent: 
  300.                     if BAND(BROTL(er.message, 8), $FF) = kSuspendResumeMessage then begin
  301.                         DoSuspendResume(BAnd(er.message, kResumeMask) <> 0);
  302.                     end;
  303.  
  304.                 DiskEvt: 
  305.                     DoDiskEvent(er.message);
  306.  
  307.                 kHighLevelEvent: 
  308.                     if has_AppleEvents then begin
  309.                         junk := AEProcessAppleEvent(er);
  310.                     end; (* if *)
  311.                 otherwise
  312.              (* do nothing *)
  313.             end; (* case *)
  314.         end;
  315.     end; (* HandleEvents *)
  316.  
  317. end. (* ICEvents *)